package com.dw.message.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dw.message.mapper.MessageUserMapper;
import com.dw.model.message.entitys.MessageUser;
import com.dw.message.service.MessageUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 聊天用户关系表(MessageUser)表服务实现类
 *
 * @author makejava
 * @since 2024-10-28 08:40:28
 */
@Service("messageUserService")
public class MessageUserServiceImpl extends ServiceImpl<MessageUserMapper, MessageUser> implements MessageUserService {

    /**
     * 根据接收人和创建人查询消息的id列表
     */
    public List<Long> queryMessageIds(Long receiveId, Long createdBy) {
        List<MessageUser> list = lambdaQuery().eq(MessageUser::getReceiveId, receiveId).eq(MessageUser::getCreatedBy, createdBy)
                .or()
                .eq(MessageUser::getReceiveId, createdBy).eq(MessageUser::getCreatedBy, receiveId).list();
        return list.stream().map(MessageUser::getMessageId).collect(Collectors.toList());
    }

}

